package cn.ccenjie.wsy.vo;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cenjunjie
 * 2019/10/11
 */
@Data
public class Resp {

    public Resp(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    String code;
    String msg;
    Object data;

    public static Resp instance(String code, String msg) {
        return new Resp(code, msg);
    }

    public static Resp ok() {
        return new Resp("200", "操作成功");
    }

    public static Resp fail(String msg) {
        return new Resp("500", msg);
    }

    public static Resp noAuth(String msg) {
        return new Resp("504", msg);
    }

    public Resp data(Object data) {
        this.setData(data);
        return this;
    }

    public Resp data(String ...data) {

        Map<String, String> map = new HashMap<>();
        for(int i=0; i<data.length; i=i+2) {
            map.put(data[i], data[i+1]);
        }
        this.setData(map);
        return this;
    }
}
